import 'package:flutter/material.dart';
import 'res/ListData.dart';

void main() {
  runApp(MyApp());
}

//自定义组件
class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    // MaterialApp是根组件
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: Text('GridView.count'),
        ),
        body: HomeContent(),
      ),
      theme: ThemeData(primaryColor: Colors.blue),
    );
  }
}

//body内容组件
class HomeContent extends StatelessWidget {
  List<Widget> _getWidgetData() {
    var tempList = listData.map((value) {
      return Container(
        alignment: Alignment.center,
        child: Column(
          children: [
            Text(
              'title ${value['title']}',
              style: TextStyle(color: Colors.black, fontSize: 20),
            )
          ],
        ),
        decoration: BoxDecoration(
            border: Border.all(
                color: Color.fromRGBO(233, 233, 233, 0.9), width: 1)),
      );
    });
    return tempList.toList();
  }

  @override
  Widget build(BuildContext context) {
    return GridView.count(
      children: _getWidgetData(),
      crossAxisCount: 2,
      crossAxisSpacing: 20.0,
      mainAxisSpacing: 20.0,
    );
  }
}
